﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace PROSHOP.DAL
{
    public class CTDDHDAL
    {
        ProshopDataContext proshop;

        public CTDDHDAL()
        {
            proshop = new ProshopDataContext();
        }

        public DataSet dsDDH(int makh)
        {
            try
            {
                var s = from kh in proshop.KhachHangs
                        from ct in proshop.CTDDHs
                        from dh in proshop.DDHs
                        from gh in proshop.HinhThucGHs
                        from tt in proshop.HinhThucTTs
                        from sp in proshop.SanPhams
                        where sp.MaSP == ct.MaSP && kh.MaKhachHang == dh.MaKH && dh.MaDDH == ct.MaDDH && dh.MaHTGH == gh.MaHTGH && dh.MaPTTT == tt.MaHTTT && dh.MaKH == makh
                        select new
                        {
                            dh.MaKH,
                            dh.MaDDH,
                            gh.TenHTGH,
                            gh.PhiGiaoHang,
                            tt.TenHTTT,
                            tt.PhiThanhToan,
                            dh.NgayLap,
                            ct.MaSP,
                            ct.SoLuong,
                            dh.TongTien
                        };
                SqlCommand cmd = (SqlCommand)proshop.GetCommand(s);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);
                return ds;
            }
            catch (Exception)
            {
                
                return null;
            }
        }
       
    }
}